<template>
  <div class="edu-page-warp">
    <div class="edu-page-title mg-top">缓存</div>
    <el-card shadow="never" body-style="padding: 24px;">
      数据字典缓存
      <el-form>
        <el-row :gutter="24">
          <el-col :span="6">
            <el-button @click="reloadDictCache">重新加载</el-button>
          </el-col>
        </el-row>
      </el-form>
      选课学生
      <el-form :model="elec" ref="elecForm" label-position="left" label-width="100px">
        <el-row :gutter="24">
          <el-col :span="6">
            <el-form-item label="轮次ID">
              <el-input
                v-model="elec.roundId"
                :rules="[{ required: true, message: '请输入轮次ID', trigger: 'blur' }]"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="学号">
              <el-input
                v-model="elec.studentId"
                :rules="[ { required: true, message: '请输入学号', trigger: 'blur' }]"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="管理部门">
              <el-input
                v-model="elec.projectId"
                :rules="[ { required: true, message: '请输入学号', trigger: 'blur' }]"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-button @click="clearElecCache">清除缓存</el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <div class="edu-page-title mg-top">排课数据处理</div>
    <el-button @click="arrangeProfile('start')">开始处理</el-button>
    <el-button @click="arrangeProfile('log')">查看处理过程</el-button>
    <el-button @click="arrangeProfile('cancel')">取消</el-button>
    <pre>{{processLog}}</pre>
  </div>
</template>
<script>
import { refreshCache } from "common/src/api/dictionary";
import arrangeProfile from "common/src/api/coursearrangement/dataprocess.js";

import fetch from "common/src/utils/fetch";

export default {
  name: "CacheManage",
  data() {
    return {
      elec: { roundId: "", studentId: "", projectId: ''},
      processLog: "",
    };
  },
  methods: {
    arrangeProfile(type){
      let promise;
      switch (type) {
        case "start":
          promise = arrangeProfile.start();
          break;
        case "log":
          promise = arrangeProfile.log();
          break;
        case "cancel":
          promise = arrangeProfile.cancel();
          break;
      }
      promise.then(res=>this.processLog = res);
    },
    reloadDictCache() {
      refreshCache().then(res => {
        this.$message({
          type: "success",
          message: this.$t("common.tips.opSuccess")
        });
      });
    },
    clearElecCache() {
      this.$refs.elecForm.validate(pass => {
        if (pass) {
          fetch({
            url: `/api/electionservice/agentElc/clearCache`,
            method: "post",
            data: this.elec
          }).then(res => {
            this.$message({
              type: "success",
              message: this.$t("common.tips.opSuccess")
            });
          });
        }
      });
    }
  },
  mounted() {}
};
</script>
<style lang="scss" scoped>
</style>
